package com.blb.demo2;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

/**
 * 负责写的线程
 */
public class WriteRunnable implements Runnable{

    public ObjectOutputStream objectOutputStream=null;

    public WriteRunnable(ObjectOutputStream objectOutputStream) {
        this.objectOutputStream = objectOutputStream;
    }

    @Override
    public void run() {
        Scanner scanner = new Scanner(System.in);

        try {
            while (true){
                //输入消息发给对方
                System.out.println("请输入要说的话");
                String s = scanner.nextLine();
                objectOutputStream.writeUTF(s);
                objectOutputStream.flush();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
